package com.vlong.town.controller.client.insurance;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.insurance.InsuranceInfo;
import com.vlong.town.service.insurance.InsuranceInfoService;
import com.vlong.town.util.data.DataUtil;
import com.vlong.town.util.pagination.PageTag;

/**
 * 农牧保险控制器
 * @author 51088
 */
@Controller
@RequestMapping("/client/insurance")
public class InsuranceClientController extends BaseController{
	@Autowired
	private InsuranceInfoService  insuranceInfoService;//业务接口
	
	/**
	 * 保险列表查询
	 * @param pageNo
	 * @param pageSize
	 * @return String
	 */
	@RequestMapping("/list")
	public  String   list(
			@RequestParam(required=false, value="pageNo") Integer pageNo,
            @RequestParam(required=false, value="pageSize") Integer pageSize
			){
		  	PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
	        PageHelper.orderBy("create_time DESC");
	        List<InsuranceInfo> queryList = insuranceInfoService.queryList(null, null, null, null);
	        PageInfo<InsuranceInfo> pageInfo = new PageInfo<InsuranceInfo>(queryList);
	        PageTag<InsuranceInfo> pt = new PageTag<InsuranceInfo>(request, "list", pageInfo);
	        request.setAttribute("pageHtml", pt.getPageHtml());
	        for(InsuranceInfo insuranceInfo : queryList) {
	        	insuranceInfo.setThumbnail(request.getScheme()+"://"+request.getServerName()+":"+ request.getServerPort() + request.getContextPath() + "/cdkeditor/" + insuranceInfo.getThumbnail());
	        	insuranceInfo.setContent(DataUtil.delHTMLTag(insuranceInfo.getContent(), 0));
	            Long createTime = insuranceInfo.getCreateTime();
	        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
	        	Date date = new  Date(createTime);
	        	String format = sdf.format(date);
	        	String createDate="["+format+"]";
	        	insuranceInfo.setCreateDate(createDate);
	        }
	        request.setAttribute("insuranceInfoList", queryList);
	        //获取SESSION信息
	  		String telphone = getTelphone();
	  		request.setAttribute("telphone", telphone);
		return  "client/insurance/list_insurance";
	}
	
	
	 /**
		 * 进去详情页面
		 * @param goodsId
		 * @return
		 */
		@RequestMapping("/detail/{insuranceId}")
		public String detail(@PathVariable(required=false, value="insuranceId") String insuranceId){
			InsuranceInfo insuranceInfo = insuranceInfoService.queryById(Long.parseLong(insuranceId));
			request.setAttribute("insuranceInfo", insuranceInfo);
			 //获取SESSION信息
	  		String telphone = getTelphone();
	  		request.setAttribute("telphone", telphone);
			return "client/insurance/detail_insurance";
		}

}
